jsx3.Class.defineClass(
        "tibco.admin.monitormanage.uicomponents.table.services.Services", //This class includes the components Filter and the Search Table together .
        jsx3.gui.Block, //  extends
        null, // implements
        function (plugin) {
            plugin.wsEndpointURL = tibco.admin.monitormanage.framework.mainPage.MainPage.wsEndpointURL;
            plugin.wsEndpointURLForSearchStaticData = "/amxadministrator/services/monuisearch";
            plugin.wsEndpointURLForSearchDynamicData = "/amxadministrator/services/monuifiltersearch";
            plugin.serviceViewScreenId = "tibco.admin.monitormanage.uicomponents.page.serviceView.ServiceView.searchServicesScreen";
            plugin.girdViewScreenId = "tibco.admin.monitormanage.uicomponents.page.gridInfrastructure.GridInfrastructure.nodeScreen";
            plugin.deploymentViewScreenId = "tibco.admin.monitormanage.uicomponents.page.deployment.Deployment.serviceUnitScreen";
            plugin.serviceSearchResultSubject = "com.tibco.admin.monitormanage.uicomponents.table.services.Services.services";
            plugin.searchParametersSubject = "com.tibco.admin.monitormanage.uicomponents.table.services.Services.services.searchParametersSubject";
            plugin.component="COMPONENT";
            plugin.compositeService="COMPOSITE_SERVICE";
            plugin.compositeReference="COMPOSITE_REFERENCE";
            plugin.isServiceInstanceMode = false;
            plugin.prototype.isFilterPaneOn = false;
            plugin.prototype.currentMetric = "";
            plugin.prototype.serviceUnitId ="";
            plugin.prototype.nodeId="";
            plugin.prototype.currentScreenId;
			plugin.prototype.nameSuffix = "";



            plugin.prototype.init = function() {
                this.jsxsuper();
            }
            plugin.prototype.getNamespace = function() {
                return "tibco.admin";
            }
            plugin.prototype.setUpComponent = function(nameSuffix, screenId,isServiceInstanceMode) {
                // This method is called in service view to set up the component
                this.isFilterPaneOn = false;
	            this.currentMetric = "";
	            this.nodeId="";
	            this.currentScreenId = null;
				this.nameSuffix = "";
				plugin.clearTableCache();
                
				var server = tibco.admin.Main.getServer();
				if (nameSuffix) {
					this.nameSuffix = nameSuffix;
					var servicesLbl = this.getDescendantOfName("servicesLbl");
					servicesLbl.setName(servicesLbl.getName() + nameSuffix);
					var servicesHelpImg = this.getDescendantOfName("servicesHelpImg");
					servicesHelpImg.setName(servicesHelpImg.getName() + nameSuffix);
					var filterImage = this.getDescendantOfName("filterImage");
					filterImage.setName(filterImage.getName() + nameSuffix);
					var implTypeSelect = this.getDescendantOfName("implTypeSelect");
					implTypeSelect.setName(implTypeSelect.getName() + nameSuffix);
					var resetButton = this.getDescendantOfName("resetButton");
					resetButton.setName(resetButton.getName() + nameSuffix);
				}

                plugin.isServiceInstanceMode = isServiceInstanceMode;
                this.setImageURL(this);
                this.loadDualSlider(this);
                this.getDescendantOfName("servicesHelpImg" + this.nameSuffix).setEvent("this.getAncestorOfName('servicesBlock').servicesHelpImgClicked(objEVENT)", "jsxexecute");
                if(plugin.isServiceInstanceMode)
                this.getDescendantOfName("servicesLbl" + this.nameSuffix).setText(server.getDynamicProperty("@MM@general@ServiceInstancesTitle"));
                else
                this.getDescendantOfName("servicesLbl" + this.nameSuffix).setText(server.getDynamicProperty("@MM@general@ServicesTitle"));
                this.getDescendantOfName("servicesLbl" + this.nameSuffix).repaint();

                tibco.admin.monitormanage.general.PageBusUtils.subscribe(tibco.admin.monitormanage.general.NavigationHandler.mainPageDisplayTopic,  this.getScreenId,this);

                if(screenId==plugin.serviceViewScreenId){
                topic = tibco.admin.monitormanage.uicomponents.misc.serviceSearch.ServiceSearch.serviceSearchSubject;
                tibco.admin.monitormanage.general.PageBusUtils.subscribe(topic, this.callgetStaticData, this);
                //tibco.admin.monitormanage.general.PageBusUtils.subscribe(tibco.admin.monitormanage.uicomponents.misc.serviceSearch.ServiceSearch.serviceSearchSubjectForBrowse, this.callgetStaticData, this);
                }

                if(screenId==plugin.deploymentViewScreenId){
                 if(this.serviceUnitId!=undefined && this.serviceUnitId!=null )
                 this.getServices(this);
                }
				tibco.admin.monitormanage.general.PageBusUtils.subscribe(tibco.admin.monitormanage.uicomponents.dropdown.timeframe.Timeframe.selectedTimeframeSubject, this.timeframeSelected, this);

                tibco.admin.monitormanage.general.PollingHandler.register(tibco.admin.monitormanage.general.PollingHandler.GENERAL_POLLING_HANDLER_ID, this, this.updateComponentForServiceView, plugin.serviceViewScreenId);
                tibco.admin.monitormanage.general.RefreshHandler.register(this, this.updateComponentForServiceView, plugin.serviceViewScreenId);

            }
            
            plugin.clearTableCache = function() {
            	tibco.admin.Main.getServer().Cache.clearById("SPM_SERVICE_SEARCH_SCREEN_CACHE", true);
	           	tibco.admin.Main.getServer().Cache.clearById("SPM_SERVICE_SEARCH_FILTERED_CACHE_DOCUMENT", true);
            }
            
            plugin.prototype.servicesHelpImgClicked = function (objEVENT) { 
                if (plugin.isServiceInstanceMode)
                    this.getDescendantOfName("servicesHelpImg" + this.nameSuffix).openHelp("MonitorManage.Infrastructure.ServiceInstances", "tibco.admin", objEVENT);
                else
                    this.getDescendantOfName("servicesHelpImg" + this.nameSuffix).openHelp("MonitorManage.Deployment.Services", "tibco.admin", objEVENT);
            }
			
            plugin.prototype.timeframeSelected = function(subject, message, tableObj) {
                if(tableObj.currentScreenId==plugin.serviceViewScreenId)   {
                        var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                        if( service_search_cache.getChildNodes().size()){
                         var msg = { initialized:true}
                         tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.searchParametersSubject, msg);
                        }    
               }
               else{
                            if( plugin.isServiceInstanceMode ) {
                            tableObj.getServiceInstances("","",tableObj);
                        } else {
                            tableObj.getServices(tableObj);
                        }
                }
            }

            plugin.prototype.setServiceUnitId =function(serviceUnitId){
               this.serviceUnitId = serviceUnitId;
            }

            plugin.prototype.getScreenId = function(subject,message,obj){
	            plugin.clearTableCache();
            
				var server = tibco.admin.Main.getServer();
                 obj.currentScreenId= message.screenId;
                 if (message.screenId==plugin.girdViewScreenId)
                 {
                   plugin.isServiceInstanceMode =true;

                   obj.getServiceInstances("",message,obj)
                }
                 if(message.screenId==plugin.deploymentViewScreenId)
                 {
                    plugin.isServiceInstanceMode =false;
                    obj.serviceUnitId= message.serviceUnitId;
		    obj.getServices(obj);
                 }
                  if(message.screenId==plugin.serviceViewScreenId && !message.isFrmBrowse)
                 {

                    plugin.isServiceInstanceMode =false;
                 }


                 if(plugin.isServiceInstanceMode)
                obj.getDescendantOfName("servicesLbl" + obj.nameSuffix).setText(server.getDynamicProperty("@MM@general@ServiceInstancesTitle"));
                else
                obj.getDescendantOfName("servicesLbl" + obj.nameSuffix).setText(server.getDynamicProperty("@MM@general@ServicesTitle"));
                obj.getDescendantOfName("servicesLbl" + obj.nameSuffix).repaint();
             }

            plugin.prototype.updateComponentForGridInfrastructure = function() {
            	this.getServiceInstances("","",this);
			}

			plugin.prototype.updateComponentForDeployment = function() {
            	this.getServices(this);
			}
            plugin.prototype.updateComponentForServiceView = function() {
                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                if( service_search_cache.getChildNodes().size()){
                /* var msg = { initialized:true}
                 tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.searchParametersSubject, msg);*/
                 if(plugin.isServiceInstanceMode ){
                  this.callgetServiceInstancesRuntimeData(this);
                 }
                 else{
                  this.callgetServicesRuntimeData(this);
                 }
                }
            }


            plugin.prototype.reset = function() {
                this.getDescendantOfName("implTypeSelect" + this.nameSuffix).setValue("All Types");
                this.resetDualSliders();
                this.filterTableData("All Types");

            }

             plugin.prototype.callgetStaticData = function (subject, message, obj){
				var server = tibco.admin.Main.getServer();
                 if(message.isServiceInstance){
                     obj.callgetServiceInstancesStaticData(message,obj);
                      plugin.isServiceInstanceMode =true;

                 }
                 else{
                    obj.callgetServicesStaticData(message,obj);
                     plugin.isServiceInstanceMode =false;
                  }

                if(plugin.isServiceInstanceMode) {
					obj.getDescendantOfName("servicesLbl" + obj.nameSuffix).setText(server.getDynamicProperty("@MM@general@ServiceInstancesTitle"));
				} else {
					obj.getDescendantOfName("servicesLbl" + obj.nameSuffix).setText(server.getDynamicProperty("@MM@general@ServicesTitle"));
				}
                obj.getDescendantOfName("servicesLbl" + obj.nameSuffix).repaint();
             }

            plugin.prototype.setImageURL = function (obj) {
                var filterimg = obj.getDescendantOfName("filterImage" + obj.nameSuffix);
                var imagePath = "jsxaddin://user!MatrixAdmin/images/matrix/arrow.gif";
                //filterimg.setSrc(tibco.admin.Main.resolveURI(this.getNamespace(), imagePath));
                filterimg.setSrc(imagePath);
                filterimg.setWidth("12");
                filterimg.setHeight("16");
                filterimg.repaint();
            }

            plugin.prototype.loadDualSlider = function (obj)
            {
                var hitsSliderBlock = obj.getDescendantOfName("hitsSliderBlock");
                if (!jsx3.ext || !jsx3.ext.DualSlider)
                {
                    tibco.admin.Main.loadClass("tibco/admin/monitormanage/uicomponents/misc/dualSlider/DualSlider.js", obj.getNamespace());
                }
                var hitsSliderComponent = tibco.admin.Main.loadUIResource(hitsSliderBlock, obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/dualSlider/components/DualSlider.xml", true);
                hitsSliderComponent.setName("hitsDualSlider" + this.nameSuffix);
               // hitsSliderComponent.fireChangeEvent = plugin.prototype.handleDualSliderMove;
                hitsSliderComponent.setEvent("var serviceBlk = this.getAncestorOfName('servicesBlock'); serviceBlk.handleDualSliderMove();", "jsxclick");
                this.initiateDualSlider(hitsSliderComponent.getName(), 0, 100);

                var faultsSliderBlock = obj.getDescendantOfName("faultsSliderBlock");
                var faultsSliderComponent = tibco.admin.Main.loadUIResource(faultsSliderBlock, obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/dualSlider/components/DualSlider.xml", true);
                faultsSliderComponent.setName("faultsDualSlider" + this.nameSuffix);
               // faultsSliderComponent.fireChangeEvent = plugin.prototype.handleDualSliderMove;
                faultsSliderComponent.setEvent("var serviceBlk = this.getAncestorOfName('servicesBlock'); serviceBlk.handleDualSliderMove();", "jsxclick");
                this.initiateDualSlider(faultsSliderComponent.getName(), 0, 100);
            };

            plugin.prototype.handleDualSliderMove = function() {
                //this.filterTableData(tibco.admin.Main.getServer().getJSXByName("implTypeSelect").getText());
                this.filterTableData(this.getDescendantOfName("implTypeSelect" + this.nameSuffix).getText());
            };

            plugin.prototype.resetDualSliders = function() {
                //var hitsDualSlider = tibco.admin.Main.getServer().getJSXByName("hitsDualSlider");
                var hitsDualSlider = this.getDescendantOfName("hitsDualSlider" + this.nameSuffix);
                //var faultsDualSlider = tibco.admin.Main.getServer().getJSXByName("faultsDualSlider");
                var faultsDualSlider = this.getDescendantOfName("faultsDualSlider" + this.nameSuffix);

                hitsDualSlider.setValue1(hitsDualSlider.getMinValue());
                hitsDualSlider.setValue2(hitsDualSlider.getMaxValue());

                faultsDualSlider.setValue1(faultsDualSlider.getMinValue());
                faultsDualSlider.setValue2(faultsDualSlider.getMaxValue());
            };

            plugin.prototype.initiateDualSlider = function(dualSliderName, minVal, maxVal) {
                //var dualSliderInstance = tibco.admin.Main.getServer().getJSXByName(dualSliderName);
                var dualSliderInstance = this.getDescendantOfName(dualSliderName);
                dualSliderInstance.jsxminval = minVal;
                dualSliderInstance.jsxmaxval = maxVal;
                dualSliderInstance.getText1().setValue(minVal);
                dualSliderInstance.getText2().setValue(maxVal);
            };

            plugin.prototype.setDualSliderMinMax = function(dualSliderName, sourceXmlCacheDocName) {
                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument(sourceXmlCacheDocName);
                noofRecords = service_search_cache.getChildNodes().size();
                var faultsHits = 0;
                var currentRecord = null;
                var currentRecordHitCount = 0;
                var minHitCount = -1, maxHitCount = -1;

                for (var i = 0; i < noofRecords; i++) {
                    currentRecord = service_search_cache.getChildNodes().get(i);
                    currentRecordHitCount = currentRecord.getAttribute("hitCount");

                    if (minHitCount == -1 && maxHitCount == -1) {
                        minHitCount = currentRecordHitCount;
                        maxHitCount = currentRecordHitCount;
                    } else {
                        if (currentRecordHitCount < minHitCount)
                            minHitCount = currentRecordHitCount;

                        if (currentRecordHitCount > maxHitCount)
                            maxHitCount = currentRecordHitCount;
                    }
                }

               this.initiateDualSlider(dualSliderName, minHitCount * 1, maxHitCount * 1);
            };

            plugin.showServiceDetail = function(serviceId) {    // link to navigate to service instance

                var paramArray ;
                var screenId;
                if (!plugin.isServiceInstanceMode)
                {
                     paramArray = { serviceId:serviceId };
                    screenId = tibco.admin.monitormanage.uicomponents.page.serviceView.ServiceView.serviceScreenId;
                }
                else
                {
                    paramArray = { serviceInstanceId:serviceId };
                    screenId = tibco.admin.monitormanage.uicomponents.page.serviceView.ServiceView.serviceInstanceScreenId;
                }
                tibco.admin.monitormanage.general.NavigationHandler.publishMainPageNavigationMessage(screenId, paramArray);
            }


            plugin.prototype.toggleFilterPane = function(obj) {   //to toggle the filter pane
                var collapseIconElement = obj.getFirstChild();
                var filterDetailsFrame = this.getDescendantOfName("filterFramesLayout");
                var displayFilterDetails = new Array("0","0","62","2","5","*");
                var hideFilterDetails = new Array("0","20","0","2","5","*");

                //toggle flag
        				this.isFilterPaneOn = !this.isFilterPaneOn;
        				//collapseIconElement.setSrc(tibco.admin.Main.resolveURI(this.getNamespace(), this.getCollapseIconSrc(this.isFilterPaneOn)));
        				collapseIconElement.setSrc(this.getCollapseIconSrc(this.isFilterPaneOn));
        				collapseIconElement.repaint();

        				if (this.isFilterPaneOn)                                //display filter details
                    filterDetailsFrame.setDimensionArray(displayFilterDetails, true);
                else                                                //hide filter details
                    filterDetailsFrame.setDimensionArray(hideFilterDetails, true);
              }


            plugin.prototype.getCollapseIconSrc = function(isOpen) {   //return collapse image icon source path
                if (!isOpen)
                    return "jsxaddin://user!MatrixAdmin/images/matrix/arrowDown.gif";        //open
                else
                    return "jsxaddin://user!MatrixAdmin/images/matrix/arrow.gif";            //close
            }


            plugin.prototype.populateImplTypeSelect = function() { // Populate the implementation type select box
                var obj = this;
                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                noofRecords = service_search_cache.getChildNodes().size();

                var ImplementationTypeSelect = obj.getDescendantOfName("implTypeSelect" + this.nameSuffix);
                var ImplementationTypeDoc = new jsx3.xml.Document();
                ImplementationTypeDoc.loadXML(ImplementationTypeSelect.getXMLString());
                for (var i = 0; i < noofRecords; i++) {
                    value = service_search_cache.getChildNodes().get(i).getAttribute("implType");

                    if (value != null) {
                        if (ImplementationTypeDoc.selectSingleNode("//record[@jsxid='" + value + "']") == null) {
                            var recordElement = ImplementationTypeDoc.createNode(jsx3.xml.Entity.TYPEELEMENT, "record", "");
                            recordElement.setAttribute("jsxid", value);
                            recordElement.setAttribute("jsxtext", value);
                            ImplementationTypeDoc.appendChild(recordElement, "jsxroot", true);
                        }
                    }

                }
                tibco.admin.Main.getServer().Cache.setDocument("SPM_SERVICE_IMPL_CACHE", ImplementationTypeDoc);

            }

            plugin.prototype.filterTableData = function(ImplType) {
                //*added lines
                //var hitsDualSlider = tibco.admin.Main.getServer().getJSXByName("hitsDualSlider");
                var hitsDualSlider = this.getDescendantOfName("hitsDualSlider" + this.nameSuffix);
				var hitsValue1 = hitsDualSlider.getValue1() * 1;
				var hitsValue2 = hitsDualSlider.getValue2() * 1;

                //var faultsDualSlider = tibco.admin.Main.getServer().getJSXByName("faultsDualSlider");
                var faultsDualSlider = this.getDescendantOfName("faultsDualSlider" + this.nameSuffix);
				var faultsValue1 = faultsDualSlider.getValue1() * 1;
				var faultsValue2 = faultsDualSlider.getValue2() * 1;

                //added lines *

				if(!isNaN(hitsValue1) && !isNaN(hitsValue2) && !isNaN(faultsValue1) && !isNaN(faultsValue2)){
                var tableXML = new jsx3.xml.Document();
                tableXML = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE").cloneDocument();


                var Hits_ResourceTypeDoc = new jsx3.xml.Document();
                var serviceTable = this.getDescendantOfName("servicesTable");
                var ResourcedataElement = Hits_ResourceTypeDoc.createDocumentElement("data", "");
                ResourcedataElement.setAttribute("jsxid", "jsxroot");

					var xQuery = "";
					if(hitsDualSlider.getMinValue() != hitsDualSlider.getMaxValue())
						xQuery = "[@hitCount >= " + hitsValue1 + " and @hitCount <= " + hitsValue2 + "]";

					var hits_resultDoc = tableXML.selectNodes("//record" + xQuery);

					if (hits_resultDoc != null) {
                for (var i = 0; i < hits_resultDoc.size(); i++)
                Hits_ResourceTypeDoc.appendChild(hits_resultDoc.get(i));

                var Hits_Faults_ResourceTypeDoc = new jsx3.xml.Document();
                var ResourcedataElement1 = Hits_Faults_ResourceTypeDoc.createDocumentElement("data", "");
                ResourcedataElement1.setAttribute("jsxid", "jsxroot");
                var faultsHitsRatio = 0;

                  for (var i = 0; i < hits_resultDoc.size(); i++){
                      faultsHitsRatio = eval(hits_resultDoc.get(i).getAttribute("faultHits")) * 100;
                      
							if(faultsDualSlider.getMinValue() != faultsDualSlider.getMaxValue()){
								if ((faultsHitsRatio >= faultsValue1) && (faultsHitsRatio <= faultsValue2))						//apply second Dual Slider
                          Hits_Faults_ResourceTypeDoc.appendChild(hits_resultDoc.get(i));
							}else{
								Hits_Faults_ResourceTypeDoc.appendChild(hits_resultDoc.get(i));
							}
                  }


                var Impl_Hits_Faults_ResourceTypeDoc = new jsx3.xml.Document();
                var ResourcedataElement2 = Impl_Hits_Faults_ResourceTypeDoc.createDocumentElement("data", "");
                ResourcedataElement2.setAttribute("jsxid", "jsxroot");
                if (Hits_Faults_ResourceTypeDoc != null) {

                    if (ImplType != "All Types") {
                        var result = Hits_Faults_ResourceTypeDoc.selectNodes("//record[@implType ='" + ImplType + "']");
                        for (var i = 0; i < result.size(); i++)
                            Impl_Hits_Faults_ResourceTypeDoc.appendChild(result.get(i));
                        tibco.admin.Main.getServer().Cache.setDocument("SPM_SERVICE_SEARCH_FILTERED_CACHE_DOCUMENT", Impl_Hits_Faults_ResourceTypeDoc);
                    }
                    else {
                        tibco.admin.Main.getServer().Cache.setDocument("SPM_SERVICE_SEARCH_FILTERED_CACHE_DOCUMENT", Hits_Faults_ResourceTypeDoc);
                        // serviceTable.setXMLId("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                    }

                    serviceTable.setXMLId("SPM_SERVICE_SEARCH_FILTERED_CACHE_DOCUMENT");
                    serviceTable.repaintData();
                }
              }
            }
		}

            plugin.prototype.getServices = function(obj) {              //Get service search results
                obj.getDescendantOfName("servicesTable").setXMLId("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                if (tibco.admin.Main.getServer().getEnv("MODE"))
                {
                    // mode is live
                    var objService = tibco.admin.Main.loadService(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/getServicesRules.xml", "getServices");
                    objService.setEndpointURL(plugin.wsEndpointURL);
                    // this setInboundURL should not be required...only here because of a current AMX framework bug
                    objService.setInboundURL("tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceSearchData.xml");
                }
                else
                {
                    var objService = new jsx3.net.Service(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/getServicesRules.xml"), "getServices", null, null);
                    // mode is static
                    objService.setInboundURL(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceSearchData.xml"));
                }


                // initialize the list of metrics we wish to retrieve data for
                var metricsList = new jsx3.util.List();
                metricsList.add("name");
                metricsList.add("version");
                metricsList.add("resourceType");
                metricsList.add("implType");
                metricsList.add("faults");
                metricsList.add("successes");
                metricsList.add("startDate");
                metricsList.add("uptime");
                metricsList.add("throughput");
                metricsList.add("avgResponseTime");
                metricsList.add("hitCount");
                objService.metricsList = metricsList;
                objService.serviceUnitId= obj.serviceUnitId  ;
                objService.timeframeId = tibco.admin.monitormanage.uicomponents.dropdown.timeframe.Timeframe.getCurrentTimeframeId();
                objService.serviceObj = obj;
                //subscribe and call
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, obj.ongetServicesSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, obj.ongetServicesError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, obj.ongetServicesInvalid);
                objService.doCall();
            };

            plugin.prototype.ongetServicesSuccess = function(objEvent) {            //success of WSDL call
                var responseXML = objEvent.target.getInboundDocument();
                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                noofRecords = service_search_cache.getChildNodes().size();
                for (var i = 0; i < noofRecords; i++) {
                    faults= service_search_cache.getChildNodes().get(i).getAttribute("faults");
                    hits=service_search_cache.getChildNodes().get(i).getAttribute("hitCount")
                    var faultsHits =faults + "/" + hits;
                    var faultsHitsValue = faults/hits ;
                    service_search_cache.getChildNodes().get(i).setAttribute("faultHitsValue", faultsHitsValue);
                    service_search_cache.getChildNodes().get(i).setAttribute("faultHits", faultsHits);
                    
                    successes = service_search_cache.getChildNodes().get(i).getAttribute("successes");
                    var faultsSuccesses = faults + "/" + successes;
                    service_search_cache.getChildNodes().get(i).setAttribute("faultSuccesses", faultsSuccesses);
                }
                objEvent.target.serviceObj.getDescendantOfName("servicesTable").repaintData();
                var message = { initialized:true,searchResults:noofRecords};
                tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.serviceSearchResultSubject, message);
                 objEvent.target.serviceObj.setDualSliderMinMax("hitsDualSlider" + objEvent.target.serviceObj.nameSuffix, "SPM_SERVICE_SEARCH_SCREEN_CACHE");
                objEvent.target.serviceObj.populateImplTypeSelect();
            };

            plugin.prototype.ongetServicesError = function(objEvent) {             //Error in WSDL call
                var myStatus = objEvent.target.getRequest().getStatus();
                jsx3.log("Error", "The service call failed. The HTTP Status code is: " + myStatus);
            };

            plugin.prototype.ongetServicesInvalid = function(objEvent) {       //Invalid WSDL call
                jsx3.log("Invalid", "The following message node just failed validation:\n\n" + objEvent.message);
            };

            plugin.prototype.getServiceInstances = function(subject, message, obj) {
                  obj.getDescendantOfName("servicesTable").setXMLId("SPM_SERVICE_SEARCH_SCREEN_CACHE");
               if(message)
                obj.nodeId = message.nodeId;
				
                if( obj.nodeId!=undefined &&  obj.nodeId!=null ){
                if (tibco.admin.Main.getServer().getEnv("MODE"))
                {
                    // mode is live
                    var objService = tibco.admin.Main.loadService(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/table/services/rules/getServiceInstancesRules.xml", "getServiceInstances");
                    objService.setEndpointURL(plugin.wsEndpointURL);
                    // this setInboundURL should not be required...only here because of a current AMX framework bug
                    objService.setInboundURL("tibco/admin/monitormanage/uicomponents/table/services/xml/serviceInstancesData.xml");
                }
                else
                {
                    var objService = new jsx3.net.Service(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/table/services/rules/getServiceInstancesRules.xml"), "getServiceInstances", null, null);
                    // mode is static
                    objService.setInboundURL(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceInstancesData.xml"));
                }


                // initialize the list of metrics we wish to retrieve data for
                var metricsList = new jsx3.util.List();
                //metricsList.add("name");
                metricsList.add("name");
                metricsList.add("version");
                metricsList.add("resourceType");
                metricsList.add("implType");
                metricsList.add("faults");
                metricsList.add("successes");
                metricsList.add("startDate");
                metricsList.add("uptime");
                metricsList.add("throughput");
                metricsList.add("avgResponseTime");
                metricsList.add("hitCount");
                objService.metricsList = metricsList;
                objService.nodeKey =obj.nodeId;
                objService.serviceObj =obj;
                objService.timeframeId = tibco.admin.monitormanage.uicomponents.dropdown.timeframe.Timeframe.getCurrentTimeframeId();
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, obj.ongetServiceInstancesSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, obj.ongetServiceInstancesError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, obj.ongetServiceInstancesInvalid);
                objService.doCall();
            }
            };

            plugin.prototype.ongetServiceInstancesSuccess = function(objEvent) {            //success of WSDL call
                var responseXML = objEvent.target.getInboundDocument();
                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                noofRecords = service_search_cache.getChildNodes().size();
                for (var i = 0; i < noofRecords; i++) {
                    var faultsHits = service_search_cache.getChildNodes().get(i).getAttribute("faults") + "/" + service_search_cache.getChildNodes().get(i).getAttribute("hitCount");
                    var faultsHitsValue = service_search_cache.getChildNodes().get(i).getAttribute("faults")/service_search_cache.getChildNodes().get(i).getAttribute("hitCount");
                    service_search_cache.getChildNodes().get(i).setAttribute("faultHitsValue", faultsHitsValue);
                    service_search_cache.getChildNodes().get(i).setAttribute("faultHits", faultsHits);

                    var faultsSuccesses = service_search_cache.getChildNodes().get(i).getAttribute("faults") + "/" + service_search_cache.getChildNodes().get(i).getAttribute("successes");
                    service_search_cache.getChildNodes().get(i).setAttribute("faultSuccesses", faultsSuccesses);
                }
               objEvent.target.serviceObj.getDescendantOfName("servicesTable").repaintData();
                var message = { initialized:true,searchResults:noofRecords};
                tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.serviceSearchResultSubject, message);
                objEvent.target.serviceObj.setDualSliderMinMax("hitsDualSlider" + objEvent.target.serviceObj.nameSuffix, "SPM_SERVICE_SEARCH_SCREEN_CACHE");
                objEvent.target.serviceObj.populateImplTypeSelect();

            };

            plugin.prototype.ongetServiceInstancesError = function(objEvent) {             //Error in WSDL call
                var myStatus = objEvent.target.getRequest().getStatus();
                jsx3.log("Error", "The service call failed. The HTTP Status code is ins%%%%%%%%%%: " + myStatus);
            };

            plugin.prototype.ongetServiceInstancesInvalid = function(objEvent) {       //Invalid WSDL call
                jsx3.log("Invalid", "The following message node just failed validation:\n\n" + objEvent.message);
            };


            /**************************************************** Static Data  for Service View ****************************************************************/

            plugin.prototype.callgetServicesStaticData = function( message, obj) {
                //Get service search results
                 obj.getDescendantOfName("servicesTable").setXMLId("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                if (tibco.admin.Main.getServer().getEnv("MODE"))
                {
                    // mode is live
                    var objService = tibco.admin.Main.loadService(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceSearchStaticDataRules.xml", "getServicesStaticData");
                    objService.setEndpointURL(plugin.wsEndpointURLForSearchStaticData);
                    // this setInboundURL should not be required...only here because of a current AMX framework bug
                    objService.setInboundURL("tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceSearchStaticData.xml");
                }
                else
                {
                    var objService = new jsx3.net.Service(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceSearchStaticDataRules.xml"), "getServicesStaticData", null, null);
                    // mode is static
                    objService.setInboundURL(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceSearchStaticData.xml"));
                }


                // initialize the list of metrics we wish to retrieve data for
                var metricsList = new jsx3.util.List();
                // metricsList.add("name");
                metricsList.add("version");
                metricsList.add("resourceType");
                metricsList.add("implType");
                metricsList.add("startDate");

                objService.metricsList = metricsList;
                objService.serviceObj = obj;

                objService.name = message.name;
                objService.resourceType = message.resourceType;
                objService.interfaceName = message.interfaceName;
                objService.namespace = message.namespace;
				objService.timeframeId = tibco.admin.monitormanage.uicomponents.dropdown.timeframe.Timeframe.getCurrentTimeframeId();;

                 objService.serviceUnitId="";
                 objService.serviceAssemblyId="";
                 objService.environmentId="";

                  if( objService.resourceType=="Component")
                 objService.resourceType=  plugin.component
                else if( objService.resourceType=="Composite Service")
                 objService.resourceType= plugin.compositeService
                else if( objService.resourceType=="Composite Reference")
                 objService.resourceType=plugin.compositeReference

                if(message.serviceUnitId){
                 objService.serviceUnitId=message.serviceUnitId ;
                }
                else if(message.serviceAssemblyId)
                {
                objService.serviceAssemblyId=message.serviceAssemblyId ;
                if(message.serviceAssemblyId=="ALL_ID")
                objService.serviceAssemblyId="";
                }
                else if(message.environmentId){
                objService.environmentId=message.environmentId ;
                }

                if( objService.resourceType==undefined)
                 objService.resourceType="";
                if( objService.name==undefined)
                 objService.name="";
                if( objService.interfaceName==undefined)
                 objService.interfaceName="";
                if( objService.namespace==undefined)
                 objService.namespace="";



                //subscribe and call
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, obj.ongetServicesStaticDataSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, obj.ongetServicesStaticDataError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, obj.ongetServicesStaticDataInvalid);
                objService.doCall();
            };

            plugin.prototype.ongetServicesStaticDataSuccess = function(objEvent) {

               objEvent.target.serviceObj.callgetServicesRuntimeData(objEvent.target.serviceObj );
                //success of WSDL call
                /* */

            };

            plugin.prototype.ongetServicesStaticDataError = function(objEvent) {             //Error in WSDL call
                var myStatus = objEvent.target.getRequest().getStatus();
                jsx3.log("Error", "The service call failed. The HTTP Status code is: " + myStatus);
            };

            plugin.prototype.ongetServicesStaticDataInvalid = function(objEvent) {       //Invalid WSDL call
                jsx3.log("Invalid", "The following message node just failed validation:\n\n" + objEvent.message);
            };

            /********************************** Run time Data for services *********************************************/
            plugin.prototype.callgetServicesRuntimeData = function(obj) {
            	var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                noofRecords = service_search_cache.getChildNodes().size();
                if(noofRecords > 0)
                {
	                if (tibco.admin.Main.getServer().getEnv("MODE"))
	                {
	                    // mode is live
	                    var objService = tibco.admin.Main.loadService(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceSearchDynamicDataRules.xml", "getServicesRuntimeData");
	                    objService.setEndpointURL(plugin.wsEndpointURLForSearchDynamicData);
	                    // this setInboundURL should not be required...only here because of a current AMX framework bug
	                    objService.setInboundURL("tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceSearchDynamicData.xml");
	                }
	                else
	                {
	                    var objService = new jsx3.net.Service(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceSearchDynamicDataRules.xml"), "getServicesRuntimeData", null, null);
	                    // mode is static
	                    objService.setInboundURL(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceSearchDynamicData.xml"));
	                }
	
	
	                var metricsList = new jsx3.util.List();
	                metricsList.add("faults");
	                metricsList.add("successes");
	                metricsList.add("uptime");
	                metricsList.add("throughput");
	                metricsList.add("avgResponseTime");
	                // metricsList.add("faultSuccRatio");
	                metricsList.add("hitCount");
	                objService.metricsList = metricsList;
	                objService.serviceObj = obj;
	                var serviceKeyList = new jsx3.util.List();
	                
	                for (var i = 0; i < noofRecords; i++) {
	                    serviceKeyList.add(service_search_cache.getChildNodes().get(i).getAttribute("serviceKey"));
	                }
	                objService.serviceKeyList = serviceKeyList;
	
	                //Method to append the services run time data to the static data document .
	                objService.appendMetric = function (val) {
	                    this.currentMetric = val;
	                    var searchDoc = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
	                    noofRecords = searchDoc.getChildNodes().size();
	                    for (var i = 0; i < noofRecords; i++) {
	                        if (objService.key == searchDoc.getChildNodes().get(i).getAttribute("serviceKey"))
	                            searchDoc.getChildNodes().get(i).setAttribute(val, "");
	                    }
	                }
	
	                objService.appendMetricValue = function (val) {
	                    var searchDoc = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
	
	                    noofRecords = searchDoc.getChildNodes().size();
	                    for (var i = 0; i < noofRecords; i++) {
	                        if (objService.key == searchDoc.getChildNodes().get(i).getAttribute("serviceKey"))
	                            searchDoc.getChildNodes().get(i).setAttribute(this.currentMetric, val);
	                    }
	
	                }
	                //subscribe and call
	                objService.subscribe(jsx3.net.Service.ON_SUCCESS, obj.ongetServicesRuntimeDataSuccess);
	                objService.subscribe(jsx3.net.Service.ON_ERROR, obj.ongetServicesRuntimeDataError);
	                objService.subscribe(jsx3.net.Service.ON_INVALID, obj.ongetServicesRuntimeDataInvalid);
	                objService.doCall();
	        	}
	        	else
				{
	                obj.getDescendantOfName("servicesTable").repaintData();
	                var message = { initialized:true,searchResults:noofRecords};
	                tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.serviceSearchResultSubject, message);
	                obj.setDualSliderMinMax("hitsDualSlider" + obj.nameSuffix, "SPM_SERVICE_SEARCH_SCREEN_CACHE");
	                obj.populateImplTypeSelect();  
				}
            };

            plugin.prototype.ongetServicesRuntimeDataSuccess = function(objEvent) {
                //var responseXML = objEvent.target.getInboundDocument();
                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                noofRecords = service_search_cache.getChildNodes().size();
                for (var i = 0; i < noofRecords; i++) {
                    faults = service_search_cache.getChildNodes().get(i).getAttribute("faults");
                    hits = service_search_cache.getChildNodes().get(i).getAttribute("hitCount");
                    if (faults != null && hits != null) {
                        var faultsHits = faults + "/" + hits ;
                        var faultsHitsValue = faults/hits ;
                        service_search_cache.getChildNodes().get(i).setAttribute("faultHitsValue", faultsHitsValue);
                        service_search_cache.getChildNodes().get(i).setAttribute("faultHits", faultsHits);

						var faultsSuccesses = faults + "/" + service_search_cache.getChildNodes().get(i).getAttribute("successes");
                    	service_search_cache.getChildNodes().get(i).setAttribute("faultSuccesses", faultsSuccesses);
                    }
                }
                objEvent.target.serviceObj.getDescendantOfName("servicesTable").repaintData();
                var message = { initialized:true,searchResults:noofRecords};
                tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.serviceSearchResultSubject, message);
                objEvent.target.serviceObj.setDualSliderMinMax("hitsDualSlider" + objEvent.target.serviceObj.nameSuffix, "SPM_SERVICE_SEARCH_SCREEN_CACHE");
                objEvent.target.serviceObj.populateImplTypeSelect();  
            };

            plugin.prototype.ongetServicesRuntimeDataError = function(objEvent) {
                var myStatus = objEvent.target.getRequest().getStatus();
                jsx3.log("Error", "The service call failed. The HTTP Status code is: " + myStatus);
            };

            plugin.prototype.ongetServicesRuntimeDataInvalid = function(objEvent) {
                jsx3.log("Invalid", "The following message node just failed validation:\n\n" + objEvent.message);
            };

            /**************************************************** Static Data  for Service Instance********************************************************/

            plugin.prototype.callgetServiceInstancesStaticData = function( message, obj) {         //Get service search results
                 obj.getDescendantOfName("servicesTable").setXMLId("SPM_SERVICE_SEARCH_SCREEN_CACHE");
                if (tibco.admin.Main.getServer().getEnv("MODE"))
                {
                    // mode is live
                    var objService = tibco.admin.Main.loadService(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceInstanceSearchStaticDataRules.xml", "getServiceInstancesStaticData");
                    objService.setEndpointURL(plugin.wsEndpointURLForSearchStaticData);
                    objService.setInboundURL("tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceInstanceStaticScreenData.xml");
                }
                else
                {
                    var objService = new jsx3.net.Service(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceInstanceSearchStaticDataRules.xml"), "getServiceInstancesStaticData", null, null);
                    // mode is static
                    objService.setInboundURL(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceInstanceStaticScreenData.xml"));
                }


                // initialize the list of metrics we wish to retrieve data for
                var metricsList = new jsx3.util.List();
                // metricsList.add("name");
                metricsList.add("version");
                metricsList.add("resourceType");
                metricsList.add("implType");
                metricsList.add("startDate");
                objService.metricsList = metricsList;
                objService.name = message.name;
                objService.resourceType = message.resourceType;
                objService.interfaceName = message.interfaceName;
                objService.namespace = message.namespace;
                objService.timeframeId = tibco.admin.monitormanage.uicomponents.dropdown.timeframe.Timeframe.getCurrentTimeframeId();

                 objService.nodeId = "";
                 objService.machineId  = "";
                 objService.environmentId = "";

                 if( objService.resourceType=="Component")
                 objService.resourceType=  plugin.component
                else if( objService.resourceType=="Composite Service")
                 objService.resourceType= plugin.compositeService
                else if( objService.resourceType=="Composite Reference")
                 objService.resourceType=plugin.compositeReference

                if(message.nodeId){
                 objService.nodeId=message.nodeId ;
                }
                else if(message.machineId)
                {
                objService.machineId=message.machineId ;
                if(message.machineId=="ALL_ID")
                objService.machineId="";
                }
                else if(message.environmentId){
                objService.environmentId=message.environmentId ;
                }


                if( objService.resourceType==undefined)
                 objService.resourceType="";
                if( objService.name==undefined)
                 objService.name="";
                if( objService.interfaceName==undefined)
                 objService.interfaceName="";
                if( objService.namespace==undefined)
                 objService.namespace="";

                 objService.serviceObj = obj;
                //subscribe and call
                objService.subscribe(jsx3.net.Service.ON_SUCCESS, obj.ongetServiceInstancesStaticDataSuccess);
                objService.subscribe(jsx3.net.Service.ON_ERROR, obj.ongetServiceInstancesStaticDataError);
                objService.subscribe(jsx3.net.Service.ON_INVALID, obj.ongetServiceInstancesStaticDataInvalid);
                objService.doCall();
            };

            plugin.prototype.ongetServiceInstancesStaticDataSuccess = function(objEvent) {
                var responseXML = objEvent.target.getInboundDocument();
               objEvent.target.serviceObj.callgetServiceInstancesRuntimeData(objEvent.target.serviceObj);
                //success of WSDL call
                /* */

            };

            plugin.prototype.ongetServiceInstancesStaticDataError = function(objEvent) {             //Error in WSDL call
                var myStatus = objEvent.target.getRequest().getStatus();
                jsx3.log("Error", "The service call failed. The HTTP Status code is: " + myStatus);
            };

            plugin.prototype.ongetServiceInstancesStaticDataInvalid = function(objEvent) {       //Invalid WSDL call
                jsx3.log("Invalid", "The following message node just failed validation:\n\n" + objEvent.message);
            };

            // ************************************Service Instance Runtime Data    *****************************************8

            plugin.prototype.callgetServiceInstancesRuntimeData = function(obj) {
            	var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICEINSTANCE_SEARCH_SCREEN_CACHE");
                noofRecords = service_search_cache.getChildNodes().size();
                if(noofRecords > 0)
                {
	                if (tibco.admin.Main.getServer().getEnv("MODE"))
	                {
	                    // mode is live
	                    var objService = tibco.admin.Main.loadService(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceInstanceSearchDynamicDataRules.xml", "getServiceInstancesRuntimeData");
	                    objService.setEndpointURL(plugin.wsEndpointURLForSearchDynamicData);
	                    // this setInboundURL should not be required...only here because of a current AMX framework bug
	                    objService.setInboundURL("tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceInstanceDynamicScreenData.xml");
	                }
	                else
	                {
	                    var objService = new jsx3.net.Service(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/rules/serviceInstanceSearchDynamicDataRules.xml"), "getServiceInstancesRuntimeData", null, null);
	                    // mode is static
	                    objService.setInboundURL(tibco.admin.Main.resolveURI(obj.getNamespace(), "tibco/admin/monitormanage/uicomponents/misc/serviceSearch/xml/serviceInstanceDynamicScreenData.xml"));
	                }
	
	
	                var metricsList = new jsx3.util.List();
	                metricsList.add("faults");
	                metricsList.add("successes");
	                metricsList.add("uptime");
	                metricsList.add("throughput");
	                metricsList.add("avgResponseTime");
	                // metricsList.add("faultSuccRatio");
	                metricsList.add("hitCount");
	                objService.metricsList = metricsList;
	                objService.serviceObj = obj;
	                objService.timeframeId = tibco.admin.monitormanage.uicomponents.dropdown.timeframe.Timeframe.getCurrentTimeframeId();
	
	                var serviceKeyList = new jsx3.util.List();
	                for (var i = 0; i < noofRecords; i++) {
	                    serviceKeyList.add(service_search_cache.getChildNodes().get(i).getAttribute("serviceKey"));
	                }
	                objService.serviceKeyList = serviceKeyList;
	                //Method to append the services Instances  run time data to the static data document .
	                objService.appendMetric = function (val) {
	                    this.currentMetric = val;
	                    var searchDoc = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICEINSTANCE_SEARCH_SCREEN_CACHE");
	                    noofRecords = searchDoc.getChildNodes().size();
	                    for (var i = 0; i < noofRecords; i++) {
	                        if (objService.key == searchDoc.getChildNodes().get(i).getAttribute("serviceKey"))
	                            searchDoc.getChildNodes().get(i).setAttribute(val, "");
	                    }
	                }
	
	                objService.appendMetricValue = function (val) {
	                    var searchDoc = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICEINSTANCE_SEARCH_SCREEN_CACHE");
	                    noofRecords = searchDoc.getChildNodes().size();
	                    for (var i = 0; i < noofRecords; i++) {
	                        if (objService.key == searchDoc.getChildNodes().get(i).getAttribute("serviceKey"))
	                            searchDoc.getChildNodes().get(i).setAttribute(this.currentMetric, val);
	                    }
	
	                }
	                //subscribe and call
	                objService.subscribe(jsx3.net.Service.ON_SUCCESS, obj.ongetServiceInstancesRuntimeDataSuccess);
	                objService.subscribe(jsx3.net.Service.ON_ERROR, obj.ongetServiceInstancesRuntimeDataError);
	                objService.subscribe(jsx3.net.Service.ON_INVALID, obj.ongetServiceInstancesRuntimeDataInvalid);
	                objService.doCall();
	        	}
	        	else
	        	{
		                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICEINSTANCE_SEARCH_SCREEN_CACHE");
		                tibco.admin.Main.getServer().Cache.setDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE", service_search_cache);
	        		obj.getDescendantOfName("servicesTable").repaintData();
                	var message = { initialized:true,searchResults:noofRecords};
                	tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.serviceSearchResultSubject, message);
               		obj.setDualSliderMinMax("hitsDualSlider" + obj.nameSuffix, "SPM_SERVICE_SEARCH_SCREEN_CACHE");
               		obj.populateImplTypeSelect();
	        	}
            };

            plugin.prototype.ongetServiceInstancesRuntimeDataSuccess = function(objEvent) {
                //var responseXML = objEvent.target.getInboundDocument();
                
                // create a mapping of the service instance ids to the sparkline urls
                var idToUrlMap = new Object();
                var runtimeDataCache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICEINSTANCE_SEARCH_DYNAMIC_CACHE");
                var runtimeDataRecords = runtimeDataCache.getChildNodes();
                for(j = 0; j < runtimeDataRecords.size(); j++)
                {
                	var runtimeDataRecord = runtimeDataRecords.get(j);
                	var recordId = runtimeDataRecord.getAttribute("serviceKey");
                	var sparklineUrl = runtimeDataRecord.getAttribute("sparklinehitsurl");
                	if(recordId && sparklineUrl)
                	{ idToUrlMap.recordId = sparklineUrl; }
                }

                var service_search_cache = tibco.admin.Main.getServer().Cache.getDocument("SPM_SERVICEINSTANCE_SEARCH_SCREEN_CACHE");
                noofRecords = service_search_cache.getChildNodes().size();
                for (var i = 0; i < noofRecords; i++) {
                	var record = service_search_cache.getChildNodes().get(i);
                	
                	// insert the sparkline url attribute into the cache doc
                	var recordId = record.getAttribute("serviceKey");
                	if(idToUrlMap.recordId)
                	{ record.setAttribute("sparklinehitsurl", idToUrlMap.recordId); }
                	
                	// insert the attributes for fault/hit and fault/success ratios into the cache doc
                    faults = record.getAttribute("faults");
                    hits = record.getAttribute("hitCount");

                    if (faults != null && hits != null) {
                        var faultsHits = faults + "/" + hits ;
                        var faultsHitsValue = faults/hits ;
                        record.setAttribute("faultHitsValue", faultsHitsValue);
                        record.setAttribute("faultHits", faultsHits);
                        var faultsSuccesses = faults + "/" + record.getAttribute("successes");
                        record.setAttribute("faultSuccesses", faultsSuccesses);
                    }
                }
                tibco.admin.Main.getServer().Cache.setDocument("SPM_SERVICE_SEARCH_SCREEN_CACHE", service_search_cache);
                objEvent.target.serviceObj.getDescendantOfName("servicesTable").repaintData();
                var message = { initialized:true,searchResults:noofRecords};
                tibco.admin.monitormanage.general.PageBusUtils.publish(plugin.serviceSearchResultSubject, message);
               objEvent.target.serviceObj.setDualSliderMinMax("hitsDualSlider" + objEvent.target.serviceObj.nameSuffix, "SPM_SERVICE_SEARCH_SCREEN_CACHE");
               objEvent.target.serviceObj.populateImplTypeSelect();
            };

            plugin.prototype.ongetServiceInstancesRuntimeDataError = function(objEvent) {
                var myStatus = objEvent.target.getRequest().getStatus();
                jsx3.log("Error", "The service call failed. The HTTP Status code is: " + myStatus);
            };

            plugin.prototype.ongetServiceInstancesRuntimeDataInvalid = function(objEvent) {
                jsx3.log("Invalid", "The following message node just failed validation:\n\n" + objEvent.message);
            };



            /**
             * Call this method when mouse move on any matrix cell.
             */
            plugin.serviceUptime_servicesTable_Spyglass = function(root, strRECORDID, objCOLUMN) 
                {
                    if(objCOLUMN.getName() == "upTimeCol")
                        {
                            if(root.getRecord(strRECORDID) != null)
                                {
                                    var uptimeVal = root.getRecord(strRECORDID).uptime;
                                    if(uptimeVal != null)
                                        return "<div style='width:90;'>" + tibco.admin.monitormanage.general.MonitorManageUtils.formatElapsedTime(uptimeVal) + "</div>";
                                }

                        }

                    if(objCOLUMN.getName() == "implementationTypeCol")
                        {
                            if(root.getRecord(strRECORDID) != null)
                                {
                                    var impltypeVal = root.getRecord(strRECORDID).implType;
                                    if(impltypeVal != null)
                                        return "<div style='width:120;'>" + impltypeVal + "</div>";
                                }
                        }

                    if(objCOLUMN.getName() == "startDateCol")
                        {
                            if(root.getRecord(strRECORDID) != null)
                                {
                                    var startDateVal = root.getRecord(strRECORDID).startDate;
                                    if(startDateVal != null)
                                        return "<div style='width:125;'>" + tibco.admin.monitormanage.general.MonitorManageUtils.formatDateISO(startDateVal) + "</div>";
                                }
                        }
                };


        });
